package com.bootdo.jiashan.controller;

import com.bootdo.jiashan.service.ImportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.servlet.http.HttpServletRequest;
import java.io.*;
import java.util.List;

/**
 * @Author: hje
 * @Description:
 * @Date: 2019-05-26 01:26
 */
@Controller
public class ImportController {
    @Autowired
    private ImportService importService;


    @PostMapping(value = "/upload")
    @ResponseBody
    public String uploadExcel(HttpServletRequest request) throws Exception {
//        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
//
//        MultipartFile file = multipartRequest.getFile("filename");
//        if (file.isEmpty()) {
//            return "文件不能为空";
//        }
//        InputStream inputStream = file.getInputStream();
//        List<List> list = importService.getBankListByExcel(inputStream, file.getOriginalFilename());
//        inputStream.close();
//
//        for (int i = 0; i < list.size(); i++) {
//            List lo = list.get(i);
//            //TODO 随意发挥
//            System.out.println(lo);
//
//        }
        return "上传成功";
    }

    public static void main(String[] args) throws Exception {
        String filepath = "/Users/hejinen/git/Mylibrary/my/aa.xlsx";
        InputStream is = new FileInputStream(filepath);
        ImportService importService = new ImportService();
//        importService.aa(is, "aa.xlsx");
//        List<List> list = importService.getBankListByExcel(is, "aa.xlsx");
        is.close();

//        for (int i = 0; i < list.size(); i++) {
//            List lo = list.get(i);
//            //TODO 随意发挥
//            System.out.println(lo);
//
//        }
    }
}

